package offer;

public class offerII_0002 {
    public String addBinary(String a, String b) {
        int len1=a.length();
        int len2=b.length();
        int max_len=Math.max(len1,len2);
        String s="";
        int flag=0;
        for(int i=0;i<max_len;++i){
            int x=0;
            int y=0;

            if(len1-i-1>=0) {
                x=a.charAt(len1-1-i)-'0';
            }
            if(len2-i-1>=0) {
                y=b.charAt(len2-1-i)-'0';
            }
            x=x+y+flag;
            flag=0;
            if(x>=2) {
                x-=2;
                flag=1;
            }
            s=x+s;
        }
        if(flag==1) s="1"+s;
        return s;
    }
}
